package com.dongqi.camera.controller;

import com.dongqi.camera.dto.CameraDTO;
import com.dongqi.camera.service.CameraService;
import com.dongqi.camera.vo.SafeCameraUrlVo;
import com.dongqi.utils.RestResult;
import com.dongqi.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/camera")
public class CameraController {
    @Autowired
    private CameraService cameraService;


    @GetMapping("/queryAll")
    public RestResult queryAll() {
        List<CameraDTO> cameraList = cameraService.queryAll();
        return RestResult.success(cameraList);
    }


    @GetMapping("/queryByCameraId")
    public RestResult queryByCameraId(@RequestParam String deviceNo) {
        if (StringUtils.isEmpty(deviceNo)) {
            return RestResult.error("传入参数有误");
        }
        //        String url = "ezopen://open.ys7.com/AF1574343/1.hd.live";
        //        safeCameraUrlVo.setUrl(url);
        SafeCameraUrlVo safeCameraUrlVo = cameraService.queryByDeviceNo(deviceNo);
        return RestResult.success(safeCameraUrlVo);
    }


    @GetMapping("getVideo1")
    public void getVideo1(HttpServletRequest request, HttpServletResponse response) throws Exception {
        cameraService.getVideo1(request, response);
    }

    @GetMapping("getVideo2")
    public void getVideo2(HttpServletRequest request, HttpServletResponse response) throws Exception {
        cameraService.getVideo2(request, response);
    }

    @GetMapping("getVideo3")
    public void getVideo3(HttpServletRequest request, HttpServletResponse response) throws Exception {
        cameraService.getVideo3(request, response);
    }

    @GetMapping("getVideo4")
    public void getVideo4(HttpServletRequest request, HttpServletResponse response) throws Exception {
        cameraService.getVideo4(request, response);
    }


}
